<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="vue.js"></script>

</head>

<body style="height:3000px">
  <div id="app">
    <button @click="isShow=!isShow">{{ isShow?"消失":"显示" }}</button>
    <home v-if="isShow"></home>
  </div>
  <script>
    let Home = {
      template:`
        <div>
          <h1>
              我是组件
              {{ num }}
          </h1>
        </div>
      `,
      data(){
        return {
          num:1,
          timer:null
        }
      },
      mounted () {
       this.timer =  setInterval(()=>{
          this.num++;
          console.log(this.num);
        },1000)
         window.onscroll = function(){
          console.log(111)
        } 
      },
      beforeDestroy () {
        console.log("销毁之前")
        console.log(this.num);
        clearInterval(this.timer);
        window.onscroll = null;
      },
      destroyed () {
        console.log("销毁之后");
        console.log(this.num);
      }
    }
    new Vue({
      el: "#app",
      data:{
        isShow:true
      },
      components: {
        Home
      }
    })
  </script>
</body>

</html>